#include <iostream>
#include <cstdarg>
#include<cstdio>
using namespace std;

void my_printf(const char *format, ...)
{
    const char *ptr = format;
    va_list s;
    va_start(s, format);
    while (*ptr != '\0')
    {
        char ch = *ptr;
        if (ch == '%')
        {
            ++ptr;
            switch (*ptr)
            {

            case 'd':
            {
                int a = va_arg(s, int);
                cout << a; // 输出整数
                break;
            }
            case 's' :
            {
               const char* c=va_arg(s,char*);
                printf("%s",c);//输出字符串
                break;
            }

            default :
            break;
            }
        }
        else 
        {
            putchar(ch);
        }
        ptr++;
    }
    va_end(s);  
}

int my_sum(int n,...)
{
    va_list s;
    va_start(s,n);
    int sum=0;
    while(n)
    {
        sum+=va_arg(s,int);
        n--;
    }
    va_end(s);
    return sum;
}

int main()
{
    my_printf("%s %d\n","string",my_sum(2,1,2));
    return 0;
}